INPUT_FILE = "ant_in_abidjan_calls.tsv"
OUTPUT_FILE = "ant_in_abidjan_calls_well_format.tsv"
def change_format(foutput):
    with open(INPUT_FILE, 'r') as finput:
        last_id = -1
        calls = ['0']*140
        i = 0
        for line in finput:
            id, date, calls_day = line.strip().split('\t')
            if id != last_id:
                i = 0
                if (last_id != -1):
                    foutput.write(create_outputstr(last_id, calls))
                last_id = id
            calls[i] = calls_day
            i+=1
        foutput.write(create_outputstr(id, calls))  #write the last antenna info

def create_outputstr(id, calls):
    return id + '\t' + '\t'.join(calls) + '\n'

if __name__ == '__main__':
    with open(OUTPUT_FILE, 'w') as foutput:
        change_format(foutput)
